package cn.tedu.wallet.dao.repository.impl;

import cn.tedu.wallet.dao.mapper.WalletAmountMapper;
import cn.tedu.wallet.dao.repository.WalletRepository;
import cn.tedu.wallet.pojo.po.UserWalletPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;

@Repository
@Slf4j
public class WalletRepositoryImpl implements WalletRepository {

    @Autowired
    private WalletAmountMapper walletAmountMapper;

    @Override
    public void updateBalance(UserWalletPO po) {
        log.debug("{}更新余额开始,新余额：{}",po.getUserId(), po.getBalance());
        QueryWrapper<UserWalletPO> query = new QueryWrapper<>();
        query.eq("user_id", po.getUserId());
        walletAmountMapper.update(po, query);
        log.debug("{}更新余额结束",po.getUserId());
    }

    @Override
    public UserWalletPO doGetBalance(Long userId) {
        QueryWrapper<UserWalletPO> query = new QueryWrapper<>();
        log.debug("查询用户{}的钱包详情", userId);
        query.eq("user_id", userId);
        UserWalletPO userWalletPO = walletAmountMapper.selectOne(query);
        log.debug("查询用户{}的钱包详情结束,结果：{}", userId, userWalletPO);
        return userWalletPO;
    }

}
